package com.demo.modules.word.controller;

import com.demo.modules.word.common.utils.AsposeUtil;
import com.demo.modules.word.common.utils.StrUtil;
import com.demo.modules.word.domain.StrDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author MyPC
 */
@Api(tags = "word解析")
@RestController
@RequestMapping("/word")
public class OfficeController {

    @ApiOperation("下载word")
    @PostMapping("/downloadWord")
    public void downloadWord(HttpServletResponse response) {
        //报告信息
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("templates/test.docx");
        AsposeUtil.wordToPdf(inputStream, response, "test");
    }

    @ApiOperation("Str处理")
    @PostMapping("/str")
    public String str(@RequestBody StrDomain strDomain) throws IOException {
        byte[] bytes = StrUtil.compressByte(strDomain.getStr());
        System.out.println(bytes.length);
        return StrUtil.decompressByte(bytes);
    }
}
